﻿@model qltscd.Models.ScreenClient.DMLDGScreenClient

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Modules/_LayoutDanhMucNhapLieu.cshtml";
}
<script>
    function confirmXoa() {
        var idLDG = document.getElementById('idLDG').value;
        if (idLDG == null || idLDG == '-1') {
            alert("Chọn lý do trước");
        } else {
            if (confirm("Bạn có muốn xóa lý do này?")) {
                document.location = "/QuanLyThietBi/DanhMucLyDoGiam/XoaLyDoGiam?id=" + idLDG;
            }
        }
    }

    function confirmSua() {
        var idLDG = document.getElementById('idLDG').value;
        if (idLDG == null || idLDG == '-1') {
            alert("Chọn lý do trước");
        } else {
            document.location = "/QuanLyThietBi/DanhMucLyDoGiam/SuaLyDoGiam?id=" + idLDG;
        }
    }

    function onCheck(id) {
        document.getElementById('idLDG').value = id;
    }
</script>

<h2>Lý do giảm</h2>
<input type="hidden" value="-1" id="idLDG" name="idLDG"/>
@{
    Html.Telerik().Grid(Model.DSLyDoGiam)
    .Name("grdDSLDG")
    .DataKeys(keys => keys.Add(c => c.IdentityLyDoGiam))
    .Resizable(r => r.Columns(true))
    .Reorderable(r => r.Columns(true))
    .Sortable()
    .Pageable(paging => paging.Enabled(true).Style(GridPagerStyles.NextPreviousAndInput).PageSize(15))
    //.Editable(editing => editing.Mode(GridEditMode.InCell))
    .ToolBar(t => {
        t.Custom()
            .Action("Create", "DanhMucLyDoGiam")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new { @class = "t-icon t-add" })
            .Text("Thêm lý do");
        //t.SubmitChanges().ButtonType(GridButtonType.ImageAndText).SaveText("Lưu").CancelText("Hủy bỏ");
        t.Custom()
           .Text("Xóa lý do")
           .ButtonType(GridButtonType.ImageAndText)
           .Url("#")
           .HtmlAttributes(new { @onclick = "confirmXoa()" })
           .ImageHtmlAttributes(new { @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/cross.png')" });
        t.Custom()
           .Text("Sửa lý do")
           .ButtonType(GridButtonType.ImageAndText)
           .Url("#")
           .HtmlAttributes(new { @onclick = "confirmSua()" })
           .ImageHtmlAttributes(new { @style = "background-image: url('./../../../../../QuanLyThietBi/Content/Images/hammer.png')" });
        t.Custom()
            .Text("In PDF")
            .Action("ShowPdf", "DanhMucLyDoGiam")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new {
                @style = "background-image: url('./../../../../QuanLyThietBi/Content/Images/printer.png');"
            });
        t.Custom()
            .Text("Xuất Excel")
            .Action("ExportToExcel", "DanhMucLyDoGiam")
            .ButtonType(GridButtonType.ImageAndText)
            .ImageHtmlAttributes(new
            {
                @style = "background-image: url('./../../../../QuanLyThietBi/Content/Images/printer.png');"
            });
    })
    .DataBinding(databinding => {
        databinding.Server()
            .Select("Index", "DanhMucLyDoGiam");
        databinding.Ajax()
            .Select("_Index", "DanhMucLyDoGiam")
            .Insert("_Insert", "DanhMucLyDoGiam")
            .Delete("_Delete", "DanhMucLyDoGiam")
            .Update("_Update", "DanhMucLyDoGiam");
    })
    .Columns(column => {
        column.Template(
                @<text>
                    <input name="checkedRecords" type="radio" title="checkedRecords" value="@item.IdentityLyDoGiam" onclick="onCheck(@item.IdentityLyDoGiam)"/>
                </text>)
            .ClientTemplate("<input type='radio' name='checkedRecords' value='<#=IdentityLyDoGiam#>' onclick='onCheck(<#=IdentityLyDoGiam#>)'/>")
            .Title("").Width(50);
                column.Bound(o => o.MaLyDoGiam).Title("Mã Lý Do Giảm")
                    .Template(@<text> <span>@item.MaLyDoGiam</span>
                              </text>)
                    .ClientTemplate("<span><#=MaLyDoGiam#></span>");
                column.Bound(o => o.TenLyDoGiam).Title("Tên Lý Do Giảm");
                //column.Command(c => {
                //    c.Custom("Delete")
                //    .ButtonType(GridButtonType.Image)
                //    .Action("Delete", "DanhMucNhaCungCap")
                //    .ImageHtmlAttributes(new { @class = "t-icon t-delete" });     
                //}).Width(50);
    })
    .Render();
    }

        <script type="text/javascript">
            function openDetailsWindow(id) {
                var url = "/QuanLyThietBi/DanhMucLyDoGiam/Create/";
                var windowElement = $.telerik.window.create({
                    title: 'Chi Tiết Lý Do Giảm',
                    actions: ["Refresh", "Maximize", "Close"],
                    contentUrl: url,
                    modal: true,
                    resizable: true,
                    draggable: true,
                    scrollable: true,
                    visible: false,
                    width: 1000,
                    height: 650,
                    id: 'detailsview',
                    name: 'detailsview',
                    onClose: function () {
                        document.location = document.location;
                    }
                });
                var w = $(windowElement).data("tWindow");
                w.center();
                w.open();
            }
        </script>


